package model;

import java.util.Observable;
import java.util.Observer;
import java.util.Vector;

/**
 * Team EBE
 * 
 * ClassEditor.java is an intermediary with functionality to edit a given class so that 
 * views do not have to directly access the class itself; Used primarily by the 
 * class editor GUI; Currently it implements observer although we are not fully 
 * implementing the functionality yet
 *
 */
public class ClassEditor implements Observer{
	private ClassImpl classToEdit;
	public ClassEditor(ClassImpl classToEditIn){
		classToEdit = classToEditIn;
	}
	
	public void commitEdits(String nameIn, int oXIn, int oYIn, int sizeXIn, int sizeYIn, Vector<AttributeImpl> attributesIn, Vector<OperationImpl> operationsIn, boolean changedAts, boolean changedOps) {
		classToEdit.setName(nameIn);
		classToEdit.setoX(oXIn);
		classToEdit.setoY(oYIn);
		classToEdit.setWidth(sizeXIn);
		classToEdit.setHeight(sizeYIn);
		if(changedAts){
			classToEdit.setAttributes(attributesIn);
		}
		if(changedOps){
			classToEdit.setOperations(operationsIn);
		}
		
	}
	
	public void commitEdits(String nameIn){
		classToEdit.setName(nameIn);
	}
	public void update(Observable obj, Object arg){
		System.out.println("AWEFR");
		if (arg instanceof ClassImpl){
			this.classToEdit = (ClassImpl) arg;
			System.out.println("a-derp");
		}	
	}
	
	public void setClassImpl(ClassImpl changedClassImpl ){
		classToEdit = changedClassImpl;
	}
	
	public Vector<AttributeImpl> getAttributeList(){
		return classToEdit.getAttributes();
	}
	
	public Vector<OperationImpl> getOperationList(){
		return classToEdit.getOperations();
	}
	
	public void removeLastAttribute( ){
		if(classToEdit.getAttributes().size() > 0){
			classToEdit.getAttributes().remove(classToEdit.getAttributes().size() - 1);
		}
	}
	
	public void removeLastOperation( ){
		if(classToEdit.getOperations().size() > 0){
			classToEdit.getOperations().remove(classToEdit.getOperations().size() - 1);
		}
	}
	
	public String getName(){
		return classToEdit.getName();
	}
	
	public int getXPos(){
		return classToEdit.getoX();
	}
	
	public int getyPos(){
		return classToEdit.getoY();
	}
	
	public int getSizeX(){
		return classToEdit.getWidth();
	}
	
	public int getySizeY(){
		return classToEdit.getHeight();
	}
}
